﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom.Compiler;

namespace RazorTemplateEngine
{
    public class CompileErrorException : Exception
    {
        private CompilerErrorCollection innerErrors;
        private StringBuilder errorMessage;
        public CompileErrorException(CompilerErrorCollection errors)
        {
            innerErrors = errors;
        }

        public override string Message
        {
            get
            {
                if (errorMessage == null)
                {
                    errorMessage = new StringBuilder();
                    foreach (CompilerError error in innerErrors)
                    {
                        errorMessage.Append(error.ToString());
                        errorMessage.Append(Environment.NewLine);
                    }
                }
                return errorMessage.ToString();
            }
        }

        public override string ToString()
        {
            return base.ToString() + Environment.NewLine + Message;
        }
    }
}
